package com.nowcoder;

import java.util.HashMap;
import java.util.Scanner;

public class ComparePoker {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            System.out.println(solver(line));
        }
    }

    private static HashMap<String, Integer> CARD_VALUE_MAP =
            new HashMap<String, Integer>() {
                {
                    put("3", 0);
                    put("4", 1);
                    put("5", 2);
                    put("6", 3);
                    put("7", 4);
                    put("8", 5);
                    put("9", 6);
                    put("10", 7);
                    put("J", 8);
                    put("Q", 9);
                    put("K", 10);
                    put("A", 11);
                    put("2", 12);
                    put("joker", 13);
                    put("JOKER", 14);
                }
            };

    /**
     * 1.输入的牌的种类是：个子、对子、三个、四个（炸弹）、对王、顺子（5张）；不存在其他情况
     * 2.输入对两手牌，不会有相等情况
     *
     * @param line
     */
    public static String solver(String line) {
        String[] players = line.split("-");
        String[] pokers1 = players[0].split(" ");
        String[] pokers2 = players[1].split(" ");
        int len1 = pokers1.length;
        int len2 = pokers2.length;
        int val1 = CARD_VALUE_MAP.get(pokers1[0]);
        int val2 = CARD_VALUE_MAP.get(pokers2[0]);
        // 对王
        if (len1 == 2 && pokers1[0].equalsIgnoreCase("joker")
                && pokers1[1].equalsIgnoreCase("joker")) {
            return players[0];
        }
        if (len2 == 2 && pokers2[0].equalsIgnoreCase("joker")
                && pokers2[1].equalsIgnoreCase("joker")) {
            return players[1];
        }
        // 炸弹
        if(len1 == 4 && len2 != 4) {
            return players[0];
        }
        if(len1 != 4 && len2 == 4) {
            return players[1];
        }
        // 其余情况，长度不想等，无法比较，打印错误
        if (len1 != len2) {
            return "ERROR";
        }
        // 个子、对子、三个、顺子、炸弹之间相互比较
        return val1 > val2 ? players[0] : players[1];
    }
}
